package com.acoreful.acf2java.admin.modules.auth.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.acoreful.acf2java.admin.modules.auth.service.AuthService;
import com.acoreful.acf2java.admin.modules.auth.support.CurrentStaff;
import com.acoreful.acf2java.admin.modules.auth.support.annotation.Subject;
import com.acoreful.acf2java.commons.utils.HttpServletUtils;

/**
 *	登出
 */
@RequestMapping("/logout")
@Controller
public class LogoutController {
    
    @Autowired
    private AuthService authService;

    @RequestMapping(method = RequestMethod.GET)
    public String logout(@Subject(required = false) CurrentStaff currentStaff, HttpServletRequest request,
            HttpServletResponse response) {
        if (currentStaff != null) {
            HttpServletUtils.deleteCookieFromResponse(request, response, AuthService.ACCESS_TOKEN);
            authService.postLogout(currentStaff);
        }
        return "redirect:/";
    }
    
}
